/*
 * Copyright (C) 2008 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package ch.lab24.android.rtm;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class LoginActivity extends Activity {
    static final String ACTION = "ch.lab24.android.rtm.RTM_LOGIN";
    static final String EXTRA_USER = "ch.lab24.android.rtm.extra_url";

	WebView browser;
	
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.login);
        browser=(WebView)findViewById(R.id.webkit);
        browser.setWebViewClient(new Callback());
        browser.loadUrl(getUrl());
    }
        
//    @Override
//    protected void onStop()
//    {
//    	super.onStop();
//    	setResult(RESULT_OK);
//    }
    
    private String getUrl()
    {
        final Intent intent = getIntent();
        final String action = intent.getAction();
        String url = null;
    	
        if (ACTION.equals(action)) {
            final Bundle extras = intent.getExtras();
            if (extras != null) {
                url = extras.getString(EXTRA_USER);
            }
        }
        return url;    	
    }
    
    /**
     * Starts the PhotostreamActivity for the specified user.
     *
     * @param context The application's environment.
     * @param user The user whose photos to display with a PhotostreamActivity.
     */
    static void show(Context context, String url) {
        final Intent intent = new Intent(ACTION);
        intent.putExtra(EXTRA_USER, url);
        context.startActivity(intent);
    }  
    
    private class Callback extends WebViewClient {
    	public boolean shouldOverrideUrlLoading(WebView view, String url) {    	
    		return(false);
    	}
    }
}
